<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        function f(val) {
            var arr = document.getElementById(val).value.split(",");
            var newarr = new Array();
            for (var i=0;i<arr.length;i++){
                if (arr[i]%2==0){
                    newarr.push(arr[i]);
                }
            }
            if (newarr.length>0){
                document.getElementById("new").value = "["+newarr+"]";
            }else {
                document.getElementById("new").value = "此数组没有偶数";
            }
        }
    </script>
</head>
<body>
    <h3>找出数组中的偶数,返回新数组</h3>
    <font>字符串数组格式:(2,3,1,3,6):</font><input id="sz" type="text">
    <br>
    <button onclick="f('sz')">开始查找</button>
    <br>
    <input type="text" id="new"  style="border:1px solid darkorchid">
</body>
</html>